package com.powernobug.bean.vo;

import com.github.pagehelper.PageInfo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class PageVo {
    private Integer page;
    private Integer limit;
    private Integer pages;
    private long total;
    private List list;

    public static PageVo list(List list) {
        PageInfo pageInfo = new PageInfo<>(list);
        // 构造PageVo
        PageVo pageVo = PageVo.builder()
                .list(pageInfo.getList())
                .total(pageInfo.getTotal())
                .page(pageInfo.getPageNum())
                .limit(pageInfo.getPageSize())
                .pages(pageInfo.getPages())
                .build();
        return pageVo;
    }

    public static PageVo pag(List list) {
        PageInfo pageInfo = new PageInfo<>(list);
        // 根据PageInfo获取到的分页信息进行封装返回
        return PageVo.builder()
                .total(pageInfo.getTotal())
                .pages(pageInfo.getPages())
                .limit(pageInfo.getPageSize())
                .page(pageInfo.getPageNum())
                .list(pageInfo.getList())
                .build();
    }
}
